import React from 'react';
import { useDpSchema, useProps } from "@ray-js/panel-sdk";
import { Switch, Text, View } from '@ray-js/ray';
import { NavBar, Button } from '@ray-js/smart-ui';
import { IconFont } from '@/components/icon-font';
import styles from './index.module.less';
//import { IconName } from "react-icons/bs";

export function Home() {
  // const actions = useActions();
   // 项目启动时，会自动拉取 IoT 平台 productId 对应的产品 schema 信息
  const dpSchema = useDpSchema();
  console.log("dpSchema", dpSchema); // 打印查看 dpSchema 内容

  // 从设备模型中读取 dpState 数据
  const dpState = useProps(state => state); // 获取所有dpState
  console.log("dpState", dpState); // 打印查看 dpState 内容
  console.log(typeof dpState);
  let firstBtn = 'Close'
  //if (dpState.work_state === "opened") {
  //    firstBtn = 'Open'
  //}

  //const dpSwitch = useProps(state => state.status); // 获取dpCode为switch的值
  //console.log("dpSwitch", dpSwitch); // 打印查看 dpSwitch 内容

  return (
    <>
      <NavBar leftText="Chicken Coop Door 1" leftTextType="home" />
      <View>
			{Object.keys(dpSchema || {}).map((dpCode) => {
				// 遍历渲染每个功能点
				return (
					<View key={dpCode}>
						{dpCode}: {dpState[dpCode]}
					</View>
				);
			})}
		</View>

    </>
  );
}

export default Home;
